package com.egame.manage.biz.web.controller.op;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import cn.egame.common.model.PageData;
import cn.egame.common.servlet.WebUtils;
import cn.egame.ext.EnumTypeExt.OperationActivityPosition;
import cn.egame.ext.EnumTypeExt.OperationActivityRecordType;
import cn.egame.ext.op.OperationActivityInfo;

import com.egame.manage.biz.server.gc.TerminalServiceImpl;
import com.egame.manage.biz.server.op.OperationActivityServiceImpl;
import com.egame.manage.biz.web.controller.BaseController;
import com.lenovo.manager.business.domain.UserBean;

@Controller
@RequestMapping("/store/advertise")
public class AdvertiseActivityController extends BaseController{

	public AdvertiseActivityController(){		
	}
	public AdvertiseActivityController(HttpServletRequest req, HttpServletResponse resp) {
		super(req, resp);
	}
	
	@RequestMapping(value = "/list", method = {RequestMethod.GET,RequestMethod.POST})
	public ModelAndView listActivity(HttpServletRequest req, HttpServletResponse resp) throws Exception{
		if(req.getSession().getAttribute(com.egame.manage.biz.utils.ConstVar.USER_SESSION_KEY) != null){
			UserBean userBean = (UserBean) req.getSession().getAttribute(com.egame.manage.biz.utils.ConstVar.USER_SESSION_KEY);
			loginUserId = userBean.getOperatorId();
		}	
		int page = WebUtils.getInt(req,"page",0);
		int rowsOfPage = WebUtils.getInt(req,"rowsOfPage",15);
		String banner = WebUtils.getString(req, "banner","");
		int recordType = WebUtils.getInt(req, "recordTypeNum", OperationActivityRecordType.none.value());
		int position = WebUtils.getInt(req, "position", OperationActivityPosition.none.value());
		String beginTime = WebUtils.getString(req, "beginTime","");
		String endTime = WebUtils.getString(req, "endTime","");
		
		List<Integer> terminalIds = TerminalServiceImpl.getInstance().listTerminalIds(com.egame.manage.biz.utils.ConstVar.HX_TYPE);		
		OperationActivityInfo bean = new OperationActivityInfo();
		bean.setDataStatus(1);
		bean.setDescription(banner);
		bean.setRecordType(OperationActivityRecordType.lookup(recordType));
		bean.setPosition(position);
		bean.setBeginString(beginTime);
		bean.setEndString(endTime);
		List<Integer> positionList = new ArrayList<Integer>();
		positionList.add(OperationActivityPosition.widgetPosition.value());
		PageData pd = OperationActivityServiceImpl.getInstance().pageActivity(appId, loginUserId, bean, terminalIds,positionList,page, rowsOfPage);	
		ModelAndView mv = new ModelAndView("/new/op/store/advertiseList");		
		mv.addObject("typeNum",recordType);
		mv.addObject("adPos",position);
		mv.addObject("pd", pd);
		mv.addObject("pdUrl", "/store/advertise/list");
		mv.addObject("para", 0);
		mv.addObject("banner", banner);
		mv.addObject("beginTime", beginTime);
		mv.addObject("endTime", endTime);
		mv.addObject("recordType", recordType);
		mv.addObject("position", position);
		return mv;
	}
}
